package wh.ispct

import grails.converters.*

class AdminController {

	def index(){
		def sessionUser = session && session.user ? session.user as JSON : "{}"
		render (view:'index',model:["SessionUser": sessionUser])
	}
	
	def login(){
		def msg = ["success":false]
		User user = User.findByLoginId(params.loginId)
		if(user == null ){
			msg.msg = "无此用户"
		}else if(user.pwd.equals(params.pwd) == false ){
		 	msg.msg = "用户密码不正确"
		}else{
			session.user = user
			msg.success = true
			msg.user = user
		}
		render (contentType:"text/json"){
			msg
		}
	}
	
	def logout(){
		def msg = ["success":true]
		session.removeAttribute("user")
		render (contentType:"text/json"){
			msg
		}
	}
}
